package com.bqtt.tumor.demo.presentation.controller;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.tbwork.utility.toolbox.tbConvert;

import com.bqtt.tumor.demo.business.HealthUserService;
import com.bqtt.tumor.demo.entity.BodyPart;
import com.bqtt.tumor.demo.entity.City;
import com.bqtt.tumor.demo.entity.Desease;
import com.bqtt.tumor.demo.entity.DiagnosisMethod;
import com.bqtt.tumor.demo.entity.Feature;
import com.bqtt.tumor.demo.entity.HealthUser;
import com.bqtt.tumor.demo.entity.Hospital;
import com.bqtt.tumor.demo.entity.Image;
import com.bqtt.tumor.demo.entity.LabSheet;
import com.bqtt.tumor.demo.entity.LabSheetResult;
import com.bqtt.tumor.demo.entity.MedicalCase;
import com.bqtt.tumor.demo.entity.Medicine;
import com.bqtt.tumor.demo.entity.Occupation;
import com.bqtt.tumor.demo.entity.SystemUser;
import com.bqtt.tumor.demo.entity.TreatmentMethod;
import com.bqtt.tumor.demo.presentation.model.HealthUserPage;
import com.bqtt.tumor.demo.presentation.model.medical_case.MedicalCondition;
 
@Controller
@RequestMapping("/admin")
@SessionAttributes(value={"currentUser","historySearchCondition"})
public class admin {

    private static final Logger log = LoggerFactory.getLogger(admin.class);
	
    //-------------------------------------病人信息--------------------------------------------------------------
	@RequestMapping("/searchHealthUser") //默认跳转到病人信息
	public String queryHealthUser(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") HealthUser condition){	
		return health_user.queryHealthUser(user, model, condition);
	}
	
	@RequestMapping("/addHealthUser") //默认跳转到病人信息
	public String addHealthUser(@ModelAttribute("currentUser") SystemUser user,  @Valid @ModelAttribute("new_health_user") HealthUser new_health_user,RedirectAttributes passModel, BindingResult bindingResult){	
        
		return health_user.addHealthUser(user, new_health_user,passModel,bindingResult);
	}
	
	@RequestMapping("/editHealthUser") //默认跳转到病人信息
	public String editHealthUser(@ModelAttribute("currentUser") SystemUser user, RedirectAttributes model,  @Valid @ModelAttribute("edit_health_user") HealthUser edit_health_user, BindingResult bindingResult){	

		return health_user.editHealthUser(user, model, edit_health_user, bindingResult);
		
	}
	
	//-------------------------------------病例--------------------------------------------------------------
	
	/** 查询病例，支持身份证号码查询
	 * @return
	 */
	@RequestMapping("/queryMedicalCase") //默认跳转到病人信息
	public String queryMedicalCase(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") MedicalCase condtion,BindingResult bindingResult,@RequestParam(value="id_number",required=false) String id_number)
	{
		return medical_case.queryMedicalCase(user, model, condtion,id_number);
	}
	
	
	@RequestMapping("/addMedicalCase") //默认跳转到病人信息
	public String addMedicalCase(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_medical_case") MedicalCase new_medical_case,BindingResult bindingResult)
	{
		return medical_case.addMedicalCase(user, model, new_medical_case, bindingResult);
	}
	
	@RequestMapping("/editMedicalCase") //默认跳转到病人信息
	public String editMedicalCase(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_medical_case") MedicalCase edit_medical_case,BindingResult bindingResult)
	{
		return medical_case.editMedicalCase(user, model, edit_medical_case, bindingResult);
	}
	
	//-------------------------------------城市--------------------------------------------------------------
	
	@RequestMapping("/queryCity") 
	public String queryCity(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") City condtion,BindingResult bindingResult)
	{
		return city.queryCity(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addCity")
	public String addCity(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_city") City new_instance,BindingResult bindingResult)
	{
		return city.addCity(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editCity")
	public String editCity(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_city") City edit_instance,BindingResult bindingResult)
	{
		return city.editCity(user, model, edit_instance, bindingResult);
	}
		
	
	
	
	//-------------------------------------疾病--------------------------------------------------------------
	
	@RequestMapping("/queryDesease") 
	public String queryDesease(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") Desease condtion,BindingResult bindingResult)
	{
		return desease.queryDesease(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addDesease")
	public String addDesease(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_desease") Desease new_desease,BindingResult bindingResult)
	{
		return desease.addDesease(user, model, new_desease, bindingResult);
	}
	
	@RequestMapping("/editDesease")
	public String editDesease(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_desease") Desease edit_desease,BindingResult bindingResult)
	{
		return desease.editDesease(user, model, edit_desease, bindingResult);
	}

	//-------------------------------------诊断方法--------------------------------------------------------------
	
	@RequestMapping("/queryDiagnosisMethod") 
	public String queryDiagnosisMethod(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") DiagnosisMethod condtion,BindingResult bindingResult)
	{
		return diagnosis_method.queryDiagnosisMethod(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addDiagnosisMethod")
	public String addDiagnosisMethod(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_diagnosis_method") DiagnosisMethod new_instance,BindingResult bindingResult)
	{
		return diagnosis_method.addDiagnosisMethod(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editDiagnosisMethod")
	public String editDiagnosisMethod(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_diagnosis_method") DiagnosisMethod edit_instance,BindingResult bindingResult)
	{
		return diagnosis_method.editDiagnosisMethod(user, model, edit_instance, bindingResult);
	}

	//-------------------------------------特征--------------------------------------------------------------
	
	@RequestMapping("/queryFeature") 
	public String queryFeature(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") Feature condtion,BindingResult bindingResult)
	{
		return feature.queryFeature(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addFeature")
	public String addFeature(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_feature") Feature new_instance,BindingResult bindingResult)
	{
		return feature.addFeature(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editFeature")
	public String editFeature(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_feature") Feature edit_instance,BindingResult bindingResult)
	{
		return feature.editFeature(user, model, edit_instance, bindingResult);
	}

	//-------------------------------------医院--------------------------------------------------------------
	
	@RequestMapping("/queryHospital") 
	public String queryHospital(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") Hospital condtion,BindingResult bindingResult)
	{
		return hospital.queryHospital(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addHospital")
	public String addHospital(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_hospital") Hospital new_instance,BindingResult bindingResult)
	{
		return hospital.addHospital(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editHospital")
	public String editHospital(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_hospital") Hospital edit_instance,BindingResult bindingResult)
	{
		return hospital.editHospital(user, model, edit_instance, bindingResult);
	}
	

	//-------------------------------------化验单定义--------------------------------------------------------------
	
	@RequestMapping("/queryLabSheet") 
	public String queryLabSheet(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") LabSheet condtion,BindingResult bindingResult)
	{
		return lab_sheet.queryLabSheet(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addLabSheet")
	public String addLabSheet(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_lab_sheet") LabSheet new_instance,BindingResult bindingResult)
	{
		return lab_sheet.addLabSheet(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editLabSheet")
	public String editLabSheet(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_lab_sheet") LabSheet edit_instance,BindingResult bindingResult)
	{
		return lab_sheet.editLabSheet(user, model, edit_instance, bindingResult);
	}



	//-------------------------------------药物表--------------------------------------------------------------
	@RequestMapping("/queryMedicine") 
	public String queryMedicine(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") Medicine condtion,BindingResult bindingResult)
	{
		return medicine.queryMedicine(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addMedicine")
	public String addMedicine(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_medicine") Medicine new_instance,BindingResult bindingResult)
	{
		return medicine.addMedicine(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editMedicine")
	public String editMedicine(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_medicine") Medicine edit_instance,BindingResult bindingResult)
	{
		return medicine.editMedicine(user, model, edit_instance, bindingResult);
	}
	
	//-------------------------------------职业表--------------------------------------------------------------
	@RequestMapping("/queryOccupation") 
	public String queryOccupation(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") Occupation condtion,BindingResult bindingResult)
	{
		return occupation.queryOccupation(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addOccupation")
	public String addOccupation(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_occupation") Occupation new_instance,BindingResult bindingResult)
	{
		return occupation.addOccupation(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editOccupation")
	public String editOccupation(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_occupation") Occupation edit_instance,BindingResult bindingResult)
	{
		return occupation.editOccupation(user, model, edit_instance, bindingResult);
	}
	
	//-------------------------------------治疗方法--------------------------------------------------------------
	@RequestMapping("/queryTreatmentMethod") 
	public String queryTreatmentMethod(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") TreatmentMethod condtion,BindingResult bindingResult)
	{
		return treatment_method.queryTreatmentMethod(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addTreatmentMethod")
	public String addTreatmentMethod(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_treatment_method") TreatmentMethod new_instance,BindingResult bindingResult)
	{
		return treatment_method.addTreatmentMethod(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editTreatmentMethod")
	public String editTreatmentMethod(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_treatment_method") TreatmentMethod edit_instance,BindingResult bindingResult)
	{
		return treatment_method.editTreatmentMethod(user, model, edit_instance, bindingResult);
	}
	
	//-------------------------------------身体部位--------------------------------------------------
	
	@RequestMapping("/queryBodyPart") 
	public String queryBodyPart(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("condtion") BodyPart condtion,BindingResult bindingResult)
	{
		return body_part.queryBodyPart(user, model, condtion,bindingResult);
	}
	
	
	@RequestMapping("/addBodyPart")
	public String addBodyPart(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_body_part") BodyPart new_instance,BindingResult bindingResult)
	{
		return body_part.addBodyPart(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editBodyPart")
	public String editBodyPart(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_body_part") BodyPart edit_instance,BindingResult bindingResult)
	{
		return body_part.editBodyPart(user, model, edit_instance, bindingResult);
	}
	
	
	

	//-------------------------------------化验单结果定义--------------------------------------------------------------
	
	@RequestMapping("/queryLabSheetResult") 
	public String queryLabSheetResult(@ModelAttribute("currentUser") SystemUser user,  ModelMap model, @ModelAttribute("condtion") LabSheetResult condtion,BindingResult bindingResult,@RequestParam(value="case_id",required=false) Integer case_id)
	{
		return lab_sheet_result.queryLabSheetResult(user, model, condtion,bindingResult,case_id);
	}
	
	
	@RequestMapping("/addLabSheetResult")
	public String addLabSheetResult(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("new_lab_sheet_result") LabSheetResult new_instance,BindingResult bindingResult)
	{
		return lab_sheet_result.addLabSheetResult(user, model, new_instance, bindingResult);
	}
	
	@RequestMapping("/editLabSheetResult")
	public String editLabSheetResult(@ModelAttribute("currentUser") SystemUser user,  ModelMap model,@ModelAttribute("edit_lab_sheet_result") LabSheetResult edit_instance,BindingResult bindingResult)
	{
		return lab_sheet_result.editLabSheetResult(user, model, edit_instance, bindingResult);
	}
	
	//------------------------------------------------图像上传 ------------------------------------------------
	@RequestMapping("/queryImage")
	public static String queryImage(@ModelAttribute("currentUser") SystemUser user,  ModelMap model, @ModelAttribute("condtion")  Image condtion,@RequestParam(value="case_id",required=true) Integer case_id,@RequestParam(value="information1",required=false) String information1,@RequestParam(value="information2",required=false) String information2,@RequestParam(value="information3",required=false) String information3)
	{
		return image.queryImage(user, model, condtion,case_id,information1,information2,information3);
	}
	
	@RequestMapping("/uploadImage")
	public static ModelAndView uploadImage(@ModelAttribute("currentUser") SystemUser user, ModelMap model,@ModelAttribute("new_image") Image imageEnity, @RequestParam(value="imageFile",required=false) MultipartFile imageFile,BindingResult bindingResult)
	{
		return image.uploadImage(user, model, imageEnity, imageFile,bindingResult);
	}
	@RequestMapping("/deleteImage")
	public static ModelAndView deleteImage(@ModelAttribute("currentUser") SystemUser user, ModelMap model,  @RequestParam(value="case_id",required=true) Integer case_id , @RequestParam(value="image_def_id",required=true) Integer image_def_id,@RequestParam(value="type",required=true) Integer type,BindingResult bindingResult)
	{
		return image.deleteImage(user, model, case_id, image_def_id, type, bindingResult);
	}
	
	//------------------------------------------------系统管理员-----------------------------------------------
	@RequestMapping("/querySystemUser")
	public String systemUserPage(@ModelAttribute("currentUser") SystemUser user,  ModelMap model)
	{
		if(user.getSessionState() == 0)
			return "login";
		return "admin/system_user";
	}

	@RequestMapping("/queryAutoInput")
	public String queryAutoInput(@ModelAttribute("currentUser") SystemUser user,  ModelMap model)
	{
		if(user.getSessionState() == 0)
			return "login";
		return "admin/auto_input";
	}

	


	public static void main(String[]args)
	{
		Timestamp one = tbConvert.StringToTimestamp("1922-02-04 12:23:34");
		
		System.out.println(one.getTime());
	}
	
}
